limsSampleType.editPage = {

    // 样本类别
    getGridParam : function() {
        var _this = this;
        return {
            type : 'grid',
            id : 'sample-category-list-grid',
            url : limsSampleType.categoryUrl + '/queries/raw',
            columns : limsSampleType.getSampleCategoryListColumns(),
            service : 'limsSampleCategoryServiceImpl',
            deleteFormatter : function(row) {
                return row.sampleCategoryName;
            },
            onLoadSuccess : function(data) {
                if (!Gikam.isEmpty(data)) {
                    Gikam.getComp('sample-category-list-grid').activeRowByIndex(0);
                }else{
                    Gikam.getComp('sample-type-list-grid').cleanData();
                }
            },
            onRowActive : function(index, row) {
                Gikam.getAsyncComp('sample-type-list-grid').done(function(grid) {
                    grid.refresh({
                        url : limsSampleType.baseUrl + '/queries/raw',
                        requestData : {
                            sampleCategoryId_EQ : row.id
                        }
                    });
                });
            },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.INSERT',
                icon : 'add',
                onClick : function() {
                    Gikam.preInsert({
                        modalTitle : 'GIKAM.BUTTON.INSERT',
                        fields : limsSampleType.getSampleCategoryFormFields(),
                        url : limsSampleType.categoryUrl,
                        titleWidth : 100,
                        disableNotEmptyValidate : true
                    }).done(function() {
                        Gikam.getComp('sample-category-list-grid').refresh();
                    });
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DELETE',
                icon : 'remove',
                onClick : function() {
                    Gikam.getComp('sample-category-list-grid').deleteRows(limsSampleType.categoryUrl);
                }
            } ]
        }
    },

    //样本类型
    getTypeListGridParam : function() {
        let _this = this;
        return {
            type : 'grid',
            id : 'sample-type-list-grid',
            columns : limsSampleType.getSampleTypeListColumns(),
            service : 'limsSampleTypeServiceImpl',
            deleteFormatter : function(row) {
                return row.sampleTypeName;
            },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.INSERT',
                icon : 'add',
                onClick : function() {
                    let _this = this;
                    let row = Gikam.getComp('sample-category-list-grid').getActivedRow();
                    if (Gikam.isEmpty(row)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM');
                        return;
                    }
                    Gikam.preInsert({
                        modalTitle : 'GIKAM.BUTTON.INSERT',
                        fields : limsSampleType.getSampleTypeFormFields(),
                        titleWidth : 120,
                        url : limsSampleType.baseUrl,
                        param : {
                            sampleCategoryId : row.id,
                        },
                    }).done(function() {
                        Gikam.getComp('sample-type-list-grid').refresh();
                    });
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DELETE',
                icon : 'remove',
                onClick : function() {
                    Gikam.getComp('sample-type-list-grid').deleteRows(limsSampleType.baseUrl);
                }
            } ]
        }
    },

    create : function() {
        let _this = this;
        Gikam.create('layout', {
            id : 'sample-category-list-layout',
            renderTo : workspace.window.$dom,
            resize : false,
            west : {
                width : '50%',
                title : 'T_LIMS_SAMPLE_CATEGORY.SERVICE_NAME',
                items : [ this.getGridParam() ]
            },
            center : {
                title : 'T_LIMS_SAMPLE_TYPE.SERVICE_NAME',
                items : [ this.getTypeListGridParam() ]
            }

        });
    },

    init : function(param) {
        this.param = param;
        this.create();
    }
};